Make `to_xpath` stringize a non-string operand as the standard filters do.

Akinori MUSHA 10 years ago
parent
commit
4c938f14e5
2 changed files with 6 additions and 1 deletions
  1. 1 1
      app/concerns/liquid_interpolatable.rb
  2. 5 0
      spec/concerns/liquid_interpolatable_spec.rb

+ 1 - 1
app/concerns/liquid_interpolatable.rb

@@ -52,7 +52,7 @@ module LiquidInterpolatable
52 52
 
53 53
     # Escape a string for use in XPath expression
54 54
     def to_xpath(string)
55
-      subs = string.scan(/\G(?:\A\z|[^"]+|[^']+)/).map { |x|
55
+      subs = string.to_s.scan(/\G(?:\A\z|[^"]+|[^']+)/).map { |x|
56 56
         case x
57 57
         when /"/
58 58
           %Q{'#{x}'}

+ 5 - 0
spec/concerns/liquid_interpolatable_spec.rb

@@ -53,5 +53,10 @@ describe LiquidInterpolatable::Filters do
53 53
         @filter.to_xpath_roundtrip(string).should == string
54 54
       }
55 55
     end
56
+
57
+    it 'should stringize a non-string operand' do
58
+      @filter.to_xpath_roundtrip(nil).should == ''
59
+      @filter.to_xpath_roundtrip(1).should == '1'
60
+    end
56 61
   end
57 62
 end